package com.xsherl.leetcode.solution;

/**
 * @Author: sherl
 * @Date: 2021/5/24 20:57
 */
public class NumDistinct {

    public int numDistinct(String s, String t) {
        char[] chars1 = s.toCharArray();
        char[] chars2 = t.toCharArray();
        int[][] ints = new int[t.length()][s.length()];
        for (int i = 0; i < t.length(); ++i) {
            for (int j = 0; j < s.length(); ++j) {
                if (chars1[j] == chars2[i]) {
                    if (i == 0) {
                        ints[i][j] = 1;
                    } else {
                        int m = j - 1;
                        while (m >= 0) {
                            ints[i][j] += ints[i - 1][m];
                            m--;
                        }
                    }
                }
            }
        }
        int sum = 0;
        for (int j = 0; j < s.length(); ++j) {
            sum += ints[t.length() - 1][j];
        }
        return sum;
    }

}
